package com.huaqin.customer;

import com.huaqin.customer.expansion.ConfirmDialogActivity;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class Confirm {
	
	public static final String HINT_TYPE_CONFIRM = "Confirm";
	public static final String HINT_TYPE_HINT_OK = "Success";
	public static final String Extra_TITLE = "Title";
	public static final String Extra_MSG = "Msg";
	
	private static final String NONE = "None";
	private static final String  TOAST = "Toast";
	private static final String  DIALOG = "Dialog";
	private static final String CUSTOM_DIALOG = "Custom";
	
	private static final String DEFAULT_PACKAGE_NAME = "com.huaqin.customer.expansion";
	
	private boolean mConfirm = false;
	private boolean mHintSuccess = false;
	
	private String mConfirmType = NONE;
	private String mConfirmTitle;
	private String mConfirmMsg;
	
	private String mHintSuccessType = NONE;
	private String mHintSuccessTitle;
	private String mHintSuccessMsg;
	
	private String mConfirmCustomDialogName;
	private String mSuccessCustomDialogName;
	
	private String mToastOfConfirm;
	private String mToastOfSuccesst;
	
	public void setConfirmSwitch(boolean bool){
		mConfirm = bool;
	}
	
	public void setConfirmType(String type){
		mConfirmType = type;
	}
	
	public void setConfirmTitle(String title){
		mConfirmTitle = title;
	}
	
	public void setConfirmMsg(String msg){
		mConfirmMsg = msg;
	}
	
	public void setHintSuccessSwitch(boolean bool){
		mHintSuccess = bool;
	}
	
	public void setHintSuccessType(String type){
		mHintSuccessType = type;
	}
	
	public void setHintSuccessTitle(String title){
		mHintSuccessTitle = title;
	}
	
	public void setHintSuccessMsg(String msg){
		mHintSuccessMsg = msg;
	}
	
	public boolean getConfirmValues(){
		return mConfirm;
	}
	
	public boolean getHintSuccessValues(){
		return mHintSuccess;
	}
	
	public void SetConfirmCustomDialogName(String CustomDialogName){
		mConfirmCustomDialogName = CustomDialogName;
	}
	
	public void SetSuccessCustomDialogName(String CustomDialogName){
		mSuccessCustomDialogName = CustomDialogName;
	}

	public void setHintToCustomer(Context context, String HintType){
	    
		if(HINT_TYPE_CONFIRM.equals(HintType)){
		    
			if(!mConfirmType.equals(NONE)){
			    
			    if(mConfirmType.equals(TOAST)){
	                setToasthint(context, mToastOfConfirm);
	            }
	            else if(mConfirmType.equals(DIALOG)){
	                setHintDialog(context, mConfirmTitle, mConfirmMsg);
	            }
	            else if(mConfirmType.equals(CUSTOM_DIALOG)){
	                setCustomDialog(context, mConfirmCustomDialogName);
	            }
			    
			}
			
		}
		else if(HINT_TYPE_HINT_OK.equals(HintType)){
		    
			if(!mHintSuccessType.equals(NONE)){
			    
			    if(mConfirmType.equals(TOAST)){
	                setToasthint(context, mToastOfSuccesst);
	            }
	            else if(mConfirmType.equals(DIALOG)){
	                setHintDialog(context, mHintSuccessTitle, mHintSuccessMsg);
	            }
	            else if(mConfirmType.equals(CUSTOM_DIALOG)){
	                setCustomDialog(context, mSuccessCustomDialogName);
	            }
			    
			}
			
		}
		
	}
	
	@SuppressLint("ShowToast")
	private void setToasthint(Context context, String toast){
		Toast.makeText(context, toast, Toast.LENGTH_LONG);
	}
	
	private void setHintDialog(Context context, String title, String msg){
		Intent intent = new Intent(context, ConfirmDialogActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.putExtra(Extra_TITLE, title);
		intent.putExtra(Extra_MSG, msg);
		context.startActivity(intent);
	}
	
	private void setCustomDialog(Context context, String DialogName){
		if(DialogName != null){
			Intent i = new Intent();
		  	i.setClassName(DEFAULT_PACKAGE_NAME, DEFAULT_PACKAGE_NAME + DialogName);
		  	context.startActivity(i);
		}
	}
}
